﻿<UserControl x:Class="Cjc.SilverGlulxe.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:local="clr-namespace:Cjc.SilverGlulxe">

	<UserControl.Resources>

		<local:BooleanToVisibilityConverter x:Key="booleanVisibilityConverter" />

		<Style x:Key="statusText" TargetType="TextBlock">
			<Setter Property="FontFamily" Value="Courier New"/>
			<Setter Property="FontSize" Value="18"/>
			<Setter Property="Foreground" Value="White"/>
		</Style>

		<Style x:Key="historyPromptText" TargetType="TextBlock">
			<Setter Property="FontFamily" Value="Courier New"/>
			<Setter Property="FontSize" Value="18"/>
			<Setter Property="Foreground" Value="Blue"/>
		</Style>

		<Style x:Key="historyCommandText" TargetType="TextBlock">
			<Setter Property="FontFamily" Value="Courier New"/>
			<Setter Property="FontSize" Value="18"/>
			<Setter Property="FontStyle" Value="Italic"/>
			<Setter Property="Foreground" Value="Green"/>
		</Style>

		<Style x:Key="historyText" TargetType="TextBlock">
			<Setter Property="FontFamily" Value="Courier New"/>
			<Setter Property="FontSize" Value="18"/>
		</Style>

		<Style x:Key="deathText" TargetType="TextBlock">
			<Setter Property="FontFamily" Value="Courier New"/>
			<Setter Property="FontSize" Value="18"/>
			<Setter Property="Foreground" Value="Red"/>
		</Style>

		<Style x:Key="promptText" TargetType="TextBlock">
			<Setter Property="FontFamily" Value="Courier New"/>
			<Setter Property="FontSize" Value="24"/>
			<Setter Property="Foreground" Value="Blue"/>
		</Style>

		<Style x:Key="commandText" TargetType="Control">
			<Setter Property="FontFamily" Value="Courier New"/>
			<Setter Property="FontSize" Value="24"/>
			<Setter Property="Foreground" Value="Green"/>
		</Style>

		<Style x:Key="controlText" TargetType="Control">
			<Setter Property="FontSize" Value="24"/>
		</Style>

		<DataTemplate x:Key="paragraphTemplate">
			<TextBlock Loaded="OnParagraphLoaded" TextWrapping="Wrap" Margin="0,0,0,10" Style="{StaticResource historyText}"/>
		</DataTemplate>

		<DataTemplate x:Key="deathTemplate">
			<TextBlock Loaded="OnParagraphLoaded" TextWrapping="Wrap" Margin="0,0,0,10" Style="{StaticResource deathText}"/>
		</DataTemplate>

		<DataTemplate x:Key="storyItemTemplate">
			<StackPanel>
				<StackPanel Orientation="Horizontal" Visibility="{Binding HasInput, Converter={StaticResource booleanVisibilityConverter}}" Margin="0,0,0,10">
					<TextBlock Text=">" Margin="0,0,5,0" Style="{StaticResource historyPromptText}" VerticalAlignment="Center"/>
					<TextBlock Text="{Binding Input}" Style="{StaticResource historyCommandText}" VerticalAlignment="Center"/>
				</StackPanel>
				<ItemsControl ItemsSource="{Binding Death}" ItemTemplate="{StaticResource deathTemplate}"
							  Visibility="{Binding HasDeath, Converter={StaticResource booleanVisibilityConverter}}"/>
				<ItemsControl ItemsSource="{Binding Paragraphs}" ItemTemplate="{StaticResource paragraphTemplate}"/>
				<TextBlock>[Testing]</TextBlock>
<!--				<ItemsControl ItemsSource="{Binding Paragraphs}" ItemTemplate="{StaticResource paragraphTemplate}"
							  Visibility="{Binding HasOutput, Converter={StaticResource booleanVisibilityConverter}}"/>-->
			</StackPanel>
		</DataTemplate>

		<Storyboard x:Key="showSaveLoad">
			<DoubleAnimation Storyboard.TargetName="saveLoadPopup" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.5"/>
		</Storyboard>

		<Storyboard x:Key="hideSaveLoad">
			<DoubleAnimation Storyboard.TargetName="saveLoadPopup" Storyboard.TargetProperty="Opacity" To="0" Completed="OnSaveLoadHidden"/>
		</Storyboard>

		<Storyboard x:Key="showLoading">
			<DoubleAnimation Storyboard.TargetName="loading" Storyboard.TargetProperty="Opacity" To="1" BeginTime="0:0:1" Duration="0:0:1"/>
		</Storyboard>

		<Storyboard x:Key="hideLoading">
			<DoubleAnimation Storyboard.TargetName="loading" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.5" Completed="OnLoadingHidden"/>
		</Storyboard>

		<Storyboard x:Key="showPleaseWait">
			<DoubleAnimation Storyboard.TargetName="pleaseWait" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:2"/>
		</Storyboard>

	</UserControl.Resources>

	<Grid x:Name="LayoutRoot" Background="White">

		<Grid.RowDefinitions>
			<RowDefinition Height="Auto"/>
			<RowDefinition/>
			<RowDefinition Height="Auto"/>
		</Grid.RowDefinitions>

		<Border Name="statusBar" Grid.Row="0" Background="#505050" Padding="10">

			<Grid>

				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto"/>
					<ColumnDefinition/>
					<ColumnDefinition Width="Auto"/>
				</Grid.ColumnDefinitions>

				<TextBlock Grid.Column="0" Text="{Binding Location}" Style="{StaticResource statusText}"/>
				<TextBlock Grid.Column="1" Text="..." Style="{StaticResource statusText}"/>
				<StackPanel Orientation="Horizontal" Grid.Column="2">
					<TextBlock Text="{Binding Time}" Style="{StaticResource statusText}"/>
					<TextBlock Text=" / " Style="{StaticResource statusText}"/>
					<TextBlock Text="{Binding Score}" Style="{StaticResource statusText}"/>
				</StackPanel>

			</Grid>

		</Border>

		<ScrollViewer Grid.Row="1" Name="storyScroll" BorderThickness="0" Background="Transparent">

			<local:LayoutTransformControl x:Name="layoutTransform" x:FieldModifier="private">

				<StackPanel Margin="5">

					<ItemsControl Name="story" ItemTemplate="{StaticResource storyItemTemplate}"/>

					<TextBlock x:Name="pleaseWait" Style="{StaticResource historyText}" Opacity="0">Please wait...</TextBlock>

					<Grid>

						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="Auto"/>
							<ColumnDefinition/>
							<ColumnDefinition Width="Auto"/>
						</Grid.ColumnDefinitions>

						<TextBlock Grid.Column="0" Text="{Binding Prompt}" VerticalAlignment="Center" Style="{StaticResource promptText}"/>
						<TextBox Name="commandBox" Grid.Column="1" VerticalAlignment="Center" BorderThickness="0" KeyDown="OnCommandKey"
								 FontStyle="Italic" Style="{StaticResource commandText}" IsTabStop="True" TabIndex="0"/>

					</Grid>

				</StackPanel>

			</local:LayoutTransformControl>

		</ScrollViewer>

		<Grid x:Name="loading" Grid.Row="1" Opacity="0">
			<Grid.Background>
				<RadialGradientBrush>
					<GradientStop Offset="0" Color="#FFFFFFFF"/>
					<GradientStop Offset="1" Color="#00FFFFFF"/>
				</RadialGradientBrush>
			</Grid.Background>
			<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24">Loading...</TextBlock>
		</Grid>

		<Grid Grid.Row="2" Margin="5">

			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="Auto"/>
				<ColumnDefinition/>
				<ColumnDefinition Width="Auto"/>
				<ColumnDefinition Width="0.2*" MinWidth="100"/>
			</Grid.ColumnDefinitions>

			<TextBlock Grid.Column="0" Text="SilverGlulxe by Chris Cavanagh" VerticalAlignment="Bottom" FontSize="8" Foreground="#A0A0A0"/>
			<HyperlinkButton Grid.Column="1" Content="Transcript" HorizontalAlignment="Center" VerticalAlignment="Center" Click="Transcript"/>
			<TextBlock Grid.Column="2" Text="Scale" Margin="0,0,5,0" VerticalAlignment="Center"/>
			<Slider Grid.Column="3" x:Name="scaleSlider" x:FieldModifier="private" Minimum="0.5" Maximum="3" Value="1" VerticalAlignment="Center"/>

		</Grid>

		<local:SaveLoadPopup x:Name="saveLoadPopup" x:FieldModifier="private" Grid.Row="1" Visibility="Collapsed" Opacity="0"
							 ItemSelected="OnSaveLoadItemSelected" Cancelled="OnSaveLoadCancelled"/>

	</Grid>

</UserControl>